package com.atguigu.gulimall.order.domain.vo;

import com.atguigu.gulimall.order.domain.to.CreateOrderTo;
import com.atguigu.gulimall.order.entity.OrderEntity;
import lombok.*;

import java.io.Serializable;
import java.util.Arrays;

/**
 * @Description
 * @Author lhj
 * @Date 2024/5/4 15:12
 */
@Data
@Builder
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
public class SubmitOrderRespVO implements Serializable {

    private static final long serialVersionUID = 7512094887723075362L;
    
    private OrderEntity order;

    /**
     * 返回错误信息状态码
     * 1: 页面携带的访问令牌为空
     * 2: 订单令牌校验失败
     * 3: 获取收获地址不能为空
     * 4: 获取到的收货地址为空，请检查
     * 5: 获取选中购物项失败
     * 6: 没有获取到购物车
     * 7: 当前价格发生变化，请重新选择商品后提交订单
     */
    private Integer code;
    
    public String getMsg() {
        return Arrays.stream(ErrorMsg.values()).filter(code -> code.equals(this.code)).findFirst().orElse(ErrorMsg.UNKNOWN).getMsg();
    }
    
    @Getter
    @AllArgsConstructor
    public enum ErrorMsg {
        ORDER_TOKEN_IS_EMPTY(1, "页面携带的访问令牌为空"),
        ORDER_CHECK_FIELD(2, "订单令牌校验失败"),
        RECEIVE_ADDRESS_NOT_EMPTY(3, "获取收获地址不能为空"),
        GET_RECEIVE_ADDRESS_IS_EMPTY(4, "获取到的收货地址为空，请检查"),
        CHECK_CART_ITEM_FIELD(5, "获取选中购物项失败"),
        NOT_GET_CART_ITEM(6, "没有获取到购物车"),
        CURR_PRICE_CHANGE(7, "当前价格发生变化，请重新选择商品后提交订单"),
        UNKNOWN(500, "系统未知异常")
        ;
        
        private Integer code;
        
        private String msg;
    }
    
}
